package com.atguigu.service.impl;

import com.atguigu.dao.AccountDao;
import com.atguigu.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 琉
 * @create 2021-09-16 10:15
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;

    //fromId表转出账户,toId表转入账户
    @Transactional
    @Override
    public void transfer(Integer fromId, Integer toId, Double money) {
        //转出账户
        accountDao.updateAccountMoney(fromId,-money);

        //转入账户
        accountDao.updateAccountMoney(toId,money);
    }

    // 根据账户的id修改账户名
    @Transactional
    @Override
    public void updateAccountNameInner(Integer accountId, String accountName) {
        accountDao.updateAccountName(accountId,accountName);

    }

    //根据账户的id增加账户的金额
    @Transactional
    @Override
    public void updateAccountMoney(Integer accountId, Double money) {
        accountDao.updateAccountMoney(accountId,money);
    }
}
